<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            border: 1px solid #000;
        }
        body>div{
            width: 200px;
            height: 700px;
        }
        .head{
            background-color: #00bfe5;
            font-weight: bolder;
            text-align: center;
            font-size: 20px;
            cursor:pointer;
            height: 30px;
            line-height: 30px;
        }
        .body{
            background-color: ivory;
            height: 100px;
            text-align: center;
            line-height: 30px;
            display: none;
        }
        #black{
            display: block;
        }
    </style>
    <script>

        var blackObj;
        window.onload= function (){
            //得到class属性的所有元素集合
            let array = document.getElementsByClassName("head");
            blackObj=array[array.length-1];
            for (let i=0;i<array.length;i++){
                array[i].onclick= function (){
                    showBody(this);
                }
            }
        }
        function showBody(headObj){
            blackObj.nextElementSibling.style.display = "none";
            headObj.nextElementSibling.style.display = "block";
            blackObj = headObj;
        }

    </script>
</head>
<body>
  <div>
    <div class="head">好友</div>
      <div class="body">
          张无忌 <br>
          金毛狮王 <br>
          赵敏
      </div>
      <div class="head">亲人</div>
      <div class="body">
          胡歌 <br>
          霍建华 <br>
          杨幂
      </div>
      <div class="head" id="black">黑名单</div>
      <div class="body">
          吴亦凡 <br>
          郑爽 <br>
          吴秀波
      </div>
  </div>
</body>
</html>